/* ------------------------------------------------------------------
 * ClientOrder.h - functions for handling orders
 * ------------------------------------------------------------------
 * Revision History:
 * 	28/03/11 - Created file
 * 		 - Added headers for main function and definition for
 * 		   class/global vars that will handle all orders
 * ------------------------------------------------------------------
 * Development Notes:
 * 	28/03/11 - Use a define for once set of positions has been
 * 		   setup. All functions need to check:
 * 			#ifndef _POSITIONS
 * 		 - CommonDefs.h doesn't appear to be linking properly
 * 		   since need to explicitly put OrderID typedef into
 * 		   this file. Should fix this later_
 * ------------------------------------------------------------------
 */

#include <CommonDefs.h> 
#include <EClientSocketBase.h>
#include <EWrapper.h>
#include <Order.h> 
#include <PosixTestClient.h> 

#define STARTING_ORDERS 5
typedef long OrderID;

#ifndef _CLIENTORD_
#define _CLIENTORD_

// Class that handles all orders
class order_set {
	private:
		Order** outs;	// Array of outstanding orders
		int num_orders;
		int max_orders;  
		void grow_orders(void);
	public:
		order_set(void);
		~order_set(void); 	
		void add_order(OrderID id); 
		void remove_order(OrderID id); 
};   

order_set::order_set() {
	num_orders = 0;
	max_orders = STARTING_ORDERS;
	Order** outs = (Order**)malloc(max_orders*sizeof(Order*));
	for(int i = 0; i < max_orders; i++) {
		outs[i] = (Order*)malloc(sizeof(Order));
	}  
}

// Global that handles all orders
order_set* positions; 

// Place an order 
void place_order(OrderID id);  

// Cancel an order specified by 'id'
void cancel_order(OrderID id); 

// Clear all held positions
void clear_all_positions(void);  

#endif

